package com.google.firebase.quickstart.database.common.data.model;

import com.google.firebase.database.Exclude;
import com.google.firebase.database.IgnoreExtraProperties;
import com.stfalcon.chatkit.commons.models.IDialog;

import java.util.HashMap;
import java.util.Map;

/*
 * Created by troy379 on 04.04.17.
 */
@IgnoreExtraProperties
public class Dialog implements IDialog<Message> {

    public String chatId;
    public boolean isChat;
    public boolean isDelete;
    public long deleteTimestamp;
    private String id;

    public String getChatId() {
        return chatId;
    }

    private String title;
    private String lastMessage;

    private String avatar;
    private Long timestamp;

    public int unreadCount;

    public Dialog() {
        // Default constructor required for calls to DataSnapshot.getValue(Dialog.class)
    }

    public Dialog(String chatId, String avatar, String name, String lastMessage, Long timestamp, int unreadCount, boolean isChat) {
        this.chatId = chatId;
        this.avatar = avatar;
        this.title = name;
        this.lastMessage = lastMessage;
        this.timestamp = timestamp;
        this.unreadCount = unreadCount;
        this.isChat = isChat;
        this.isDelete = false;
    }

    @Exclude
    public Map<String, Object> toMap() {
        HashMap<String, Object> result = new HashMap<>();
        result.put("chatId", chatId);
        result.put("avatar", avatar);
        result.put("title", title);
        result.put("lastMessage", lastMessage);
        result.put("timestamp", timestamp);
        result.put("unreadCount", unreadCount);
        result.put("isChat", isChat);
        result.put("isDelete", isDelete);
        result.put("deleteTimestamp", deleteTimestamp);
        return result;
    }


    @Override
    public boolean isDelete() {
        return isDelete;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public String getDialogName() {
        return title;
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public String getLastMessage() {
        return lastMessage;
    }

    @Override
    public void setLastMessage(String lastMessage) {
        this.lastMessage = lastMessage;
    }

    @Override
    public int getUnreadCount() {
        return unreadCount;
    }

    public String getAvatar() {
        return avatar;
    }

    public Long getTimestamp() {
        return timestamp;
    }
}
